{layout name="layout/header" /}
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑权限</h5>
                    <div class="ibox-tools">
                        <a type="button" class="btn btn-primary btn-sm" href="{:url('rbac/node_list')}">返回列表页</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form" action="{:url('rbac/update_node')}">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">左侧菜单名/权限名称</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control"  name="name" value="{$node.name}">
                                <input type="hidden" name="id" value="{$node.id}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">控制器</label>
                            <div class="col-sm-4">
                                <input type="text" name="controller" class="form-control" value="{$node.controller}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">方法</label>
                            <div class="col-sm-4">
                                <input type="text" name="action" class="form-control" value="{$node.action}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">父节点</label>
                            <div class="col-sm-3">
                                <select class="form-control m-b parent_id" name="pid_1" pid="1" id="level_1">
                                    <option value="0">请选择</option>
                                    {volist name="$data1" id="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                            <div class="col-sm-3">
                                <select class="form-control m-b " name="pid_2" pid="2" id="level_2">
                                    <option value="0">请选择</option>
                                    {volist name="$data2" id="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">层级</label>
                            <div class="col-sm-4">
                                <select class="form-control m-b" name="level" id="level">
                                    <option value="1">一级菜单</option>
                                    <option value="2">二级菜单</option>
                                    <option value="3">仅权限</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">排序</label>
                            <div class="col-sm-4">
                                <input type="text" name="sort" class="form-control" value="{$node.sort}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<!--layer-->
<script src="root/js/plugins/layer/layer.min.js"></script>

<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>
<script>
    $(document).ready(function () {
        checks();
        //单选，复选按钮
        function checks () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green'
            })
        }

        var level = "{$node.level}";
        $('#level').val(level);
        var plevel = "{$p_level}";
        var pid = "{$node.pid}";
        if(plevel == 1){
            $('#level_1').val(pid);
        }else if(plevel ==2){
            $('#level_2').val(pid);
        }


        $('.parent_id').change(function () {
            var pid = $(this).attr('pid');
            var id = $(this).find('option:selected').val();
            var next = $(this).parent().next().children();
            $.ajax({
                type:'post',
                url:"{:url('rbac/ajax_get_node')}",
                data: {id:id},
                dataType:'json',
                success:function(data){
                    next.empty();
                    if(data.code == 1){
                        next.append("<option value='0'>请选择</option>");
                        $.each(data.data, function(k,v){
                            next.append("<option value='"+v.plat_node_id+"'>"+v.name+"</option>");
                        });
                    }

                }
            });
        })
    });

</script>
<script>
    $(function () {
        $("#form").validate({
            rules: {
                name:{required:true},
                password: {
                    required: true,
                    minlength: 6
                }
            }
        })
    })
</script>
